import { Language } from "../../../../../extend/language/Language";
import { OlympicGuessData } from "../data/OlympicGuessData";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GCheckBox } from "../../../../../com/mui/controls/GCheckBox";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GTextFormat } from "../../../../common/GTextFormat";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class OlympicGuessTodayItem
    
    export  class OlympicGuessTodayItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._isExpandable = false;
            var loc1=Language.getString(80011);
            loc1 = loc1.split("</font>")[1];
            this.index2ABC = loc1.split("   ");
            loc1 = Language.getString(80069);
            this.answerDescs = loc1.split(",");
            this.initView();
            return;
        }

        public updateData(arg1: OlympicGuessData): void
        {
            this._myData = arg1;
            this._isExpandable = !this._myData.isNotOpened;
            this._txtDate.htmlText = this._myData.date;
            if (this._myData.status != OlympicGuessData.Status_Done) 
            {
                this._txtStatus.htmlText = this._myData.status;
            }
            else 
            {
                this._txtStatus.htmlText = Language.getStringByParam(80012, this._myData.myAnswer, this._myData.answer);
            }
            if (this._myData.isDoing) 
            {
                this.drawGuessingView();
            }
            else if (this._myData.isMiss) 
            {
                this.drawMissView();
            }
            else if (this._myData.isWaitting) 
            {
                this.drawWaittingView();
            }
            else if (this._isExpandable) 
            {
                this.drawAnsweredView();
            }
            this.updateStyle();
            return;
        }

        public expandQA(): void
        {
            if (!this._isExpandable) 
            {
                return;
            }
            if (this.isExpanding) 
            {
                return;
            }
            this._spExpand.visible = true;
            if (!this._myData.isDoing) 
            {
            };
            return;
        }

        public shrinkQA(): void
        {
            if (!this.isExpanding) 
            {
                return;
            }
            this._spExpand.visible = false;
            return;
        }

        public /* override */ get width(): number
        {
            if (this.isExpanding) 
            {
                return OlympicGuessTodayItem.ExpandWidth;
            }
            return OlympicGuessTodayItem.ShrinkWidth;
        }

        public get isExpanding(): Boolean
        {
            return this._spExpand.visible;
        }

        public get myData(): OlympicGuessData
        {
            return this._myData;
        }

        /* internal  */setNotOpened(): void
        {
            return;
        }

        /* internal  */clickExpandHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!this._isExpandable) 
            {
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.OlympicClickExpandTodayGusess, this._myData));
            return;
        }

        /* internal  */clickCheckBoxHandler(arg1: Object /* flash.events.Event */): void
        {
            var evt: Object /* flash.events.Event */;
            var target: GCheckBox;
            var choose: int;
            var i: int;
            var closeAlertHandler: Function;
            var cb: GCheckBox;

            var loc1;
            choose = 0;
            closeAlertHandler = null;
            cb = null;
            evt = arg1;
            closeAlertHandler = (arg1: int): void
            {
                var loc1=0;
                var loc2=null;
                if (arg1 != Alert.YES) 
                {
                    loc1 = 0;
                    while (loc1 < _boxes.length) 
                    {
                        loc2 = _boxes[loc1] as GCheckBox;
                        loc2.selected = false;
                        ++loc1;
                    }
                    return;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.OlympicSubmitTodayGoldNum, choose + 1));
                return;
            }
            target = evt.target as GCheckBox;
            if (!target.selected) 
            {
                return;
            }
            choose = 0;
            i = 0;
            while (i < this._boxes.length) 
            {
                cb = this._boxes[i] as GCheckBox;
                if (cb != target) 
                {
                    cb.selected = false;
                }
                else 
                {
                    choose = i;
                }
                ++i;
            }
            Alert.show("你确定选择  " + this.index2ABC[choose] + "  吗？", null, Alert.YES | Alert.NO, null, closeAlertHandler);
            return;
        }

        /* internal  */updateStyle(): void
        {
            if (this._myData.isDoing) 
            {
                this.setDoingStyle();
            }
            else if (this._myData.isDone) 
            {
                this.setDoneStyle();
            }
            else if (this._myData.isWaitting) 
            {
                this.setWaitting();
            }
            else if (this._myData.isNotOpened) 
            {
                this.setNotOpenedStyle();
            }
            return;
        }

        /* internal  */setDoingStyle(): void
        {
            this._btn.enabled = true;
            this._btn.mouseEnabled = true;
            return;
        }

        /* internal  */setDoneStyle(): void
        {
            this._btn.enabled = false;
            this._btn.mouseEnabled = true;
            return;
        }

        /* internal  */setWaitting(): void
        {
            this._btn.enabled = true;
            this._btn.mouseEnabled = true;
            return;
        }

        /* internal  */setNotOpenedStyle(): void
        {
            this._btn.enabled = true;
            this._btn.mouseEnabled = false;
            return;
        }

        /* internal  */drawAnsweredView(): void
        {
            var loc2=null;
            var loc3=null;
            if (this._myData == null) 
            {
                return;
            }
            this.preDraw();
            var loc1=Language.getStringByParam(80047, this._myData.goldNum, this._myData.answer);
            loc2 = ObjCreate.createGTextField("", 50, 5, 144, 40, this._spExpand);
            loc2.mouseEnabled = false;
            loc2.htmlText = loc1;
            loc1 = Language.getStringByParam(80048, this._myData.myAnswer);
            loc2 = ObjCreate.createGTextField("", 80, 33, 120, 22, this._spExpand);
            loc2.htmlText = loc1;
            if (this._myData.isNotOpened || this._myData.isWaitting) 
            {
                return;
            }
            loc3 = new Object /* flash.display.Bitmap */();
            loc3.x = 50;
            loc3.y = 39;
            this._spExpand.addChild(loc3);
            if (this._myData.isRight()) 
            {
                loc1 = Language.getString(80050);
                loc3.bitmapData = GlobalClass.getBitmapData(ImagesConst.OlympicGuessRight);
            }
            else 
            {
                loc1 = Language.getString(80049);
                loc3.bitmapData = GlobalClass.getBitmapData(ImagesConst.OlympicGuessWrong);
            }
            loc2 = ObjCreate.createGTextField("", 80, 48, 120, 22, this._spExpand);
            loc2.htmlText = loc1;
            return;
        }

        /* internal  */drawMissView(): void
        {
            var loc1=null;
            var loc2=null;
            if (this._myData == null) 
            {
                return;
            }
            this.preDraw();
            if (this._myData.goldNum >= 0) 
            {
                loc2 = Language.getStringByParam(80047, this._myData.goldNum, this._myData.answer);
                loc1 = ObjCreate.createGTextField("", 50, 5, 144, 40, this._spExpand);
                loc1.mouseEnabled = false;
                loc1.htmlText = loc2;
            }
            else 
            {
                loc2 = Language.getString(80054);
                loc1 = ObjCreate.createGTextField("", 50, 5, 144, 40, this._spExpand);
                loc1.mouseEnabled = false;
                loc1.htmlText = loc2;
            }
            loc2 = Language.getString(80051);
            loc1 = ObjCreate.createGTextField("", 76, 38, 120, 22, this._spExpand);
            loc1.htmlText = loc2;
            return;
        }

        /* internal  */drawWaittingView(): void
        {
            if (this._myData == null) 
            {
                return;
            }
            this.preDraw();
            var loc1=ObjCreate.createGTextField("", 64, 14, 144, 20, this._spExpand, GlobalStyle.textFormat1);
            var loc2=this.answerDescs[this._myData.getAnswerIndex(this._myData.myAnswer)];
            loc1.htmlText = Language.getStringByParam(80053, loc2);
            var loc3=ObjCreate.createGTextField("", 64, 32, 144, 40, this._spExpand, new GTextFormat(null, 14));
            loc3.htmlText = Language.getString(80052);
            return;
        }

        /* internal  */preDraw(): void
        {
            if (this._spExpand != null) 
            {
                while (this._spExpand.numChildren > 0) 
                {
                    this._spExpand.removeChildAt(0);
                }
            }
            var loc1=ObjCreate.createGTextInput(43, 0, 158, 66, this._spExpand);
            loc1.mouseChildren = false;
            loc1.mouseEnabled = false;
            return;
        }

        /* internal  */drawGuessingView(): void
        {
            var loc2=null;
            var loc5=0;
            var loc6=0;
            var loc7=0;
            var loc8=0;
            var loc9=null;
            var loc10=null;
            if (this._myData == null) 
            {
                return;
            }
            this.preDraw();
            var loc1=Language.getString(80018);
            var loc3=ObjCreate.createGTextField("", 50, 5, 144, 40, this._spExpand);
            loc3.mouseEnabled = false;
            loc3.htmlText = loc1;
            this._boxes = [];
            var loc4=0;
            while (loc4 < 2) 
            {
                loc5 = 0;
                while (loc5 < 2) 
                {
                    loc6 = loc4 * 2 + loc5;
                    loc1 = this.index2ABC[loc6] as string;
                    loc7 = 45;
                    if (loc5 == 1) 
                    {
                        loc7 = 116;
                    }
                    loc8 = 22;
                    if (loc4 == 1) 
                    {
                        loc8 = 44;
                    }
                    loc1 = this.answerDescs[loc6];
                    (loc9 = ObjCreate.createGTextField("", loc7, loc8, 68, 22, this._spExpand)).htmlText = loc1;
                    loc10 = ObjCreate.createCheckBox("", loc7 + 46, loc8 - 2, 20, 20, this._spExpand);
                    if (loc5 == 1) 
                    {
                        loc10.x = loc7 + 66;
                    }
                    loc10.addEventListener(flash.events.MouseEvent.CLICK, this.clickCheckBoxHandler);
                    this._boxes.push(loc10);
                    ++loc5;
                }
                ++loc4;
            }
            return;
        }

        /* internal  */initView(): void
        {
            this._btn = ObjCreate.createGLoadedButton(ResFileConst.OlympicGuessItemBtn, 0, 0, 42, 66, this);
            this._btn.addEventListener(flash.events.MouseEvent.CLICK, this.clickExpandHandler);
            this._txtDate = ObjCreate.createGTextField("", 8, 3, 28, 40, this);
            var loc1=this._txtDate.defaultTextFormat;
            loc1.leading = 2;
            this._txtDate.defaultTextFormat = loc1;
            this._txtDate.multiline = true;
            this._txtDate.wordWrap = true;
            this._txtDate.mouseEnabled = false;
            this._txtStatus = ObjCreate.createGTextField("", 8, 33, 28, 40, this);
            loc1 = this._txtStatus.defaultTextFormat;
            loc1.leading = 4;
            this._txtStatus.defaultTextFormat = loc1;
            this._txtStatus.multiline = true;
            this._txtStatus.wordWrap = true;
            this._txtStatus.mouseEnabled = false;
            this._spExpand = new Object /* flash.display.Sprite */();
            this.addChild(this._spExpand);
            this._spExpand.visible = false;
            return;
        }

        public static /* const */ExpandWidth: int=200;

        public static /* const */ShrinkWidth: int=42;

        /* internal */ /* var */_isExpandable: Boolean;

        /* internal */ /* var */_spExpand: Object /* flash.display.Sprite */;

        /* internal */ /* var */_btn: GLoadedButton;

        /* internal */ /* var */_txtDate: GTextFiled;

        /* internal */ /* var */_txtStatus: GTextFiled;

        /* internal */ /* var */_boxes: Array<any>;

        /* internal */ /* var */_myData: OlympicGuessData;

        /* internal */ /* var */index2ABC: Array<any>;

        /* internal */ /* var */answerDescs: Array<any>;
    }
